#include <iostream>
#include "ChatServer.hpp"
#include "Route.hpp"
#include "ThreadPool.hpp"

using task_t = std::function<void()>;

void Detect(const std::string &src)
{
    std::cout << "请输入：" << src << " 端口号" << std::endl;
}

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        Detect(argv[0]);
        exit(1);
    }
    EnableConsolseSyncStrategy();
    uint16_t port = std::stoi(argv[1]);
    std::unique_ptr<Route> r = std::make_unique<Route>();
    auto tp = ThreadPool<task_t>::GetInstance();
    std::unique_ptr<ChatServer> ptr = std::make_unique<ChatServer>(port, [&r, &tp](int sockfd, std::string message, InetAddr addr){
        task_t task = std::bind(&Route::SendMessageToAll, r.get(), sockfd, message, addr);
        tp->Enqueue(task);
    });
    ptr->Init();
    ptr->Start();

    return 0;
}
                                                                   